package com.example.wdt.common.controller;


import cn.wangdian.erp.sdk.WdtErpException;
import org.springframework.security.authentication.BadCredentialsException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import lombok.extern.slf4j.Slf4j;


@Slf4j
@ControllerAdvice//表示在使用@Controller注解的类中如果出现异常就会被该类进行捕捉
public class GlobalExceptionHandler {

    @ExceptionHandler(Exception.class)
    @ResponseBody
    public ResponseResult handleException(Exception e) {
        log.error("连接服务异常信息：{}",e.getMessage());
        ResponseResult response = ResponseResult.error(500,e.getMessage());
        return response;
    }

    @ExceptionHandler(WdtErpException.class)
    @ResponseBody
    public ResponseResult handleWdtErpException(Exception e) {
        log.error("旺店通服务异常信息：{}",e.getMessage());
        ResponseResult response = ResponseResult.error(500,e.getMessage());
        return response;
    }

    @ExceptionHandler(BadCredentialsException.class)
    @ResponseBody
    public ResponseResult handleBadCredentialsException(Exception e) {
        log.error("鉴权异常信息：{}",e.getMessage());
        ResponseResult response = ResponseResult.error(500,e.getMessage());
        return response;
    }


}
